package com.huluobo.a2109mvpimdemo.addFriend;

import android.os.AsyncTask;

import com.huluobo.a2109mvpimdemo.IMApp;
import com.huluobo.a2109mvpimdemo.base.BasePresenter;
import com.hyphenate.EMCallBack;
import com.hyphenate.chat.EMClient;

/**
 * Created by LC on 2023/11/14.
 */
public class AddFriendPresenter extends BasePresenter<AddFriendContract.View> implements AddFriendContract.Presenter {
    @Override
    public void add(String username, String reason) {
        if (isAttach()) {
            if (username.matches(IMApp.REGEX_USERNAME)) {
                EMClient.getInstance().contactManager().aysncAddContact(username, reason, new EMCallBack() {
                    @Override
                    public void onSuccess() {
                        getView().onAddSuccess();
                    }

                    @Override
                    public void onError(int code, String error) {
                        getView().onAddFailed(error);
                    }
                });
            } else {
                getView().onAddFailed("用户名错误,首字符为英文需要3-20位");
            }
        }
    }
}
